package com.yejiali.backend.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.yejiali.backend.entity.dto.FollowUserDTO;
import com.yejiali.backend.entity.dto.LikeVideoDTO;
import com.yejiali.backend.entity.dto.UserDTO;
import com.yejiali.backend.response.Response;
import com.yejiali.backend.service.UserFollowService;
import com.yejiali.backend.service.UsersService;
import com.yejiali.backend.service.VideoLikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户表(Users)表控制层
 *
 * @author yejiali
 * @since 2025-07-21 15:41:47
 */
@RestController
@RequestMapping("users")
public class UsersController{

    @Autowired
    private UsersService usersService;

    @Autowired
    private UserFollowService userFollowService;

    @Autowired
    private VideoLikesService videoLikesService;

    /**
     * 查询博主详细信息
     */
    @GetMapping("/detail")
    public Response<UserDTO> getUsersDetail(@RequestParam Long userId,@RequestParam(required = false) Long loginUserId) {
        return usersService.getUsersDetail(userId,loginUserId);
    }


    /**
     * 关注用户
     */
    @PostMapping("/follow")
    public Response<String> followUser(@RequestBody FollowUserDTO followUserDTO) {
        return userFollowService.followUser(followUserDTO.getUserId(), followUserDTO.getFollowedUserId());
    }

    /**
     * 取消关注用户
     */
    @PostMapping("/unfollow")
    public Response<String> unfollowUser(@RequestBody FollowUserDTO followUserDTO) {
        return userFollowService.unfollowUser(followUserDTO.getUserId(), followUserDTO.getFollowedUserId());
    }

    /**
     * 点赞某个视频
     */
    @PostMapping("/likeVideos")
    public Response<String> likeVideo(@RequestBody LikeVideoDTO likeVideoDTO) throws JsonProcessingException {
        return videoLikesService.likeVideo(likeVideoDTO.getUserId(), likeVideoDTO.getVideoId());
    }
    /**
     * 取消点赞某个视频
     */
    @PostMapping("/unlikeVideos")
    public Response<String> unlikeVideo(@RequestBody LikeVideoDTO likeVideoDTO) {
        return videoLikesService.unlikeVideo(likeVideoDTO.getUserId(), likeVideoDTO.getVideoId());
    }

    /**
     * 模糊匹配用户昵称
     */
    @GetMapping("/searchNickName")
    public Response<?> searchUsers(@RequestParam String keyword) {
        return usersService.searchUsers(keyword);
    }

    /**
     * 随机推荐的@用户
     */
    @GetMapping("/random")
    public Response<?> randomUsers(@RequestParam Long userId) {
        return usersService.randomUsers(userId);
    }
    /**
     * 查询我的关注的用户
     */
    @GetMapping("/queryMyFollow")
    public Response<?> queryMyFollow(@RequestParam Long userId) {
        return userFollowService.queryMyFollow(userId);
    }





}

